void main() {
  Person p = new Person(name: 'O椰');
  p.eat();

  // 直接用Teacher类声明
  Teacher t = new Teacher(name: 'O椰');
  t.eat();  

  Student s = new Student(name: 'O椰');
  s.work();
}


// 声明一个通用的person类
class Person {
  String? name;
  int? age;
  String ? sex;
  double? height;
  double? weight;
  String ? hobby;

//  构造一个同名函数
Person({this.name,this.age,this.sex,this.height,this.weight,this.hobby});
eat(){
  print("${name}在吃东西");
}
sleep(){
  print("${name}在睡觉");
}
run(){
  print("${name}在跑步");
}
work(){
  print("${name}在工作");
}
}


// Teacher→继承Person类
class Teacher extends Person{
  // 继承父类构造函数
  // super 当前的父类构造函数对象
  Teacher(
    {
      String?name,
      int?age,
      String?sex,
      double?height,
      double?weight,
      String?hobby
    }):super(
      name: name,
      age: age,
      sex: sex,
      height: height,
      weight: weight,
      hobby: hobby
);

@override
  eat() {
    // TODO: implement eat
    // 重写子类方法
   print('${name}在吃火锅');
  }
}


// Student
class Student extends Person {
  Student(
      {String? name,
      int? age,
      String? sex,
      double? height,
      String? hobby,
      double? weight})
      : super(
            name: name, age: age, height: height, hobby: hobby, weight: weight);
  @override
  work() {
    // TODO: implement work
    super.work(); // 执行父类的方法
    print("$name工作完摸鱼"); // 执行自己的方法
  }
}